package com.xiaoxu.scala_base.三班._3_Scala函数高级操作

import scala.util.Random

/**
  * 偏函数：被包在花括号内没有match的一组case语句
  *   理解为match的一组case的另一种应用
  */
object PartitalFunctionApp extends App {

    val names = Array("zhangxiaozhang", "zhanglaoshi", "zhaolaoshi")
    val name = names(Random.nextInt(names.length))

    name match {
      case "zhangxiaozhang" =>  println("张校长...")
      case "zhanglaoshi"  => println("张老师....")
      case _ => println("真不知道你们在说什么....")
    }


  // A 输入参数类型    B 输出参数类型
  def sayChinese:PartialFunction[String,String] = {
    case "zhangxiaozhang" =>  "张校长..."
    case "zhanglaoshi"  => "张老师...."
    case _ =>"真不知道你们在说什么...."
  }


  println(sayChinese("Akiho Yoshizawa"))

}
